package ext.vpde.cadvaulting.migration;

import java.io.*;
import java.util.*;

public class CreateTestUsers {
	
	public static void main ( String [] args ) {
		if (args.length != 1) {
			System.out.println("\nUsage: java.ext.ncs.CreateTestUsers loadfile");
		} else {
            Hashtable ht = readUsers(args[0]);
            writeUsers(ht);
		}
    }
	
	private static Hashtable readUsers(String inputFile) {
		Hashtable uht = new Hashtable();
		try {
			BufferedReader file = LoadUtil.openInputFile(inputFile);
			if (file != null) {
				String s = file.readLine();
				int lineNumber = 0;
				while (s!= null && s.length() > 0) {
					LoadUtil.printProgress(lineNumber++);
					Hashtable ht = LoadUtil.processInputLine(s);
					String cre = ht.get("CREATOR").toString();
					if (!uht.containsKey(cre)) uht.put(cre,cre);
					String  mod = ht.get("MODIFIER").toString();
					if (!uht.containsKey(mod)) uht.put(mod,mod);
					s = file.readLine();
				}
			}
		} catch (Exception e) { LoadUtil.printException("CreateTestUsers.readUsers", e); }
		return uht;
	}
	
	private static void writeUsers(Hashtable ht) {
		try {
			PrintWriter pw = LoadUtil.openOutputFile("cadusers.xml");
			Enumeration enumeration = ht.elements();
			LoadUtil.writeXMLHeader(pw);
			while (enumeration.hasMoreElements()) {
				String user = enumeration.nextElement().toString();
				pw.println(LoadUtil.createUserXML(user));	
			}
			LoadUtil.writeXMLFooter(pw);
		} catch (Exception e) { LoadUtil.printException("CreateTestUsers.readUsers", e); }
	}
}